home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / July 96 / Re FW_CArcShape HitTest doe.1 < prev    next >
Encoding:
Internet Message Format  |  1996-07-16  |  2.1 KB  |  [TEXT/ttxt]

  1. Subject:     Re: FW_CArcShape::HitTest does not seem to work
  2. Sent:        7/15/96 3:53 PM
  3. Received:    7/15/96 4:31 PM
  4. From:        Henri Lamiraux, lamiraux@apple.com
  5. Reply-To:    ODF Interest, ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. >I have a little pie chart part that I am doing some hit testing on.  I 
  9. >want to
  10. >pass in a point to each section of the pie for hit testing to determine
  11. >which section the point is in.  However, no matter where the point is in
  12. >the pie, the first section always returns a hit.  I looked at the code and
  13. >the problem seems to be in the CalcAngle function.  I'm no mathemetician,
  14. >but it seems to me that a function that always returns zero can't be doing
  15. >what it's supposed to! :-)
  16. >
  17. >What's the deal?
  18. >Walter
  19.  
  20. This is the fix for FW_CArcShape::CalcAngle that will be in ODF Release 2:
  21.  
  22. //-------------------------------------------------------------------------
  23. ---------------
  24. //    FW_CArcShape::CalcAngle
  25. //-------------------------------------------------------------------------
  26. ---------------
  27.  
  28. short FW_CArcShape::CalcAngle(const FW_CPoint& test) const
  29. {
  30.     FW_Double width  = FW_FixedToDouble(fRect.right - fRect.left);
  31.     FW_Double height = FW_FixedToDouble(fRect.bottom - fRect.top);
  32.     
  33.     FW_CPoint testPoint(FW_Half(test.x + test.x - fRect.right - fRect.left), 
  34. FW_Half(test.y + test.y - fRect.bottom - fRect.top));
  35.     
  36.     if (testPoint.y == FW_kFixed0 || height == 0)
  37.         return testPoint.x < FW_kFixed0 ? 270 : 90;
  38.  
  39.     if (testPoint.x == FW_kFixed0 || width == 0)
  40.         return testPoint.y < FW_kFixed0 ? 180 : 0;
  41.  
  42.     FW_Double arc = atan((FW_FixedToDouble(testPoint.y) * height) / 
  43. (FW_FixedToDouble(testPoint.x) * width));
  44.     
  45.     arc = ((180.0 * arc) / 3.1415926536) + .5;
  46.     short shortArc = (short)arc + 90;
  47.     if (testPoint.x < FW_kFixed0)
  48.         shortArc += 180;
  49.                 
  50.     return shortArc;
  51. }
  52.  
  53.  
  54. ........................................................................
  55.  Henri Lamiraux                                      lamiraux@apple.com
  56.  Apple Computer, Inc.                 OpenDoc(tm) Development Framework
  57. ........................................................................
  58.  
  59.  
  60.